package com.bmoblistview;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class AddActivity extends AppCompatActivity {
    private EditText addName;
    private EditText addAge;
    private RadioButton rbBoy;
    private RadioButton rbGirl;
    private Button btnAddStu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add);

        setTitle("添加学生");

        addName = findViewById(R.id.add_name);
        addAge = findViewById(R.id.add_age);
        rbBoy = findViewById(R.id.rb_boy);
        rbGirl = findViewById(R.id.rb_girl);
        btnAddStu = findViewById(R.id.btn_addStu);

        btnAddStu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = addName.getText().toString();
                int age = Integer.parseInt(addAge.getText().toString());
                String gender = "男";
                if (rbBoy.isChecked()) {
                    gender = "男";
                } else if (rbGirl.isChecked()) {
                    gender = "女";
                }

                Intent intent = new Intent();
                intent.putExtra("NAME", name);
                intent.putExtra("AGE", age);
                intent.putExtra("GENDER", gender);
                setResult(2001, intent);
                finish();
            }
        });

    }
}
